package com.itmuch.cloud.service.impl;

import com.itmuch.cloud.feign.UserFeignClient;
import com.itmuch.cloud.pojo.User;
import com.itmuch.cloud.service.UserService;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserFeignClient userFeignClient;

    @CircuitBreaker(name = "userService", fallbackMethod = "findByIdFallback")
    @Override
    public User findById(Long id) {
        return userFeignClient.findById(id);
    }

    // 本地fallback方法
    public User findByIdFallback(Long id, Exception e) {
        User user = new User();
        user.setUsername("本地Resilience4j降级处理");
        return user;
    }
}
